package org.example.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.common.pojo.MESResult;
import com.qidian.mes.pojo.Defect;
import com.qidian.mes.pojo.Iqc;
import com.qidian.mes.pojo.TemplateIndex;
import org.example.mapper.IqcMapper;
import org.example.service.IqcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 严伟伦
 * @Company 无
 * @Description
 * @Date: 2024/10/23 11:37
 */
@Service
public class IqcServiceImpl implements IqcService {
    @Autowired
    private IqcMapper iqcMapper;
    @Override
    public MESResult selectByPage(Iqc iqc, Integer page, Integer limit) {
        // 开启分页  参数1： 页码  参数2： 每页大小,这一条下面第一个方法就是分页方法
        PageHelper.startPage(page,limit);
        // 查询全部
        List<Iqc> iqcs = iqcMapper.selectByPage(iqc);

        // 创建一个PageInfo对象，构造方法中传入查询的结果集合。
        PageInfo<Iqc> defectPageInfo = new PageInfo<>(iqcs);

        return MESResult.success(defectPageInfo);
    }

    @Override
    public MESResult addIqc(Iqc iqc) {
        if (iqcMapper.addIqc(iqc) == 1){
            return MESResult.success(iqc);
        }
        return MESResult.error();
    }

    @Override
    public MESResult selectIqcById(int iqcId) {
        Iqc iqc = iqcMapper.selectIqcById(iqcId);
        return MESResult.success(iqc);
    }

    @Override
    public MESResult updateIqc(Iqc iqc) {
        if (iqc == null){
            return MESResult.error();
        }
        if (iqcMapper.updateIqc(iqc) == 1){
            return MESResult.success();
        }
        return MESResult.error();
    }
}
